/**
 * 获取屏幕窗口安全高度和宽度
 * 注意是针对种屏幕的统一计算，统一高度，不再让uni获取有效高度而烦恼。
 * 请一定要在onMounted或者onLoad中调用，否则不准确在h5端。
 * @return {height,width,top,isCustomHeader}
 */
function window(): {
    width: number;
    height: number;
    top: number;
    bottom: number;
    isCustomHeader: Boolean;
    sysinfo: UniApp.GetSystemInfoResult;
} {
    // let getsysinfoSync = getCookie("tmui_sysinfo")
    // if(getsysinfoSync){
    // 	return getsysinfoSync
    // }
    const sysinfo = uni.getSystemInfoSync();
    let top = 0;
    let height = sysinfo.windowHeight;
    const nowPage = getCurrentPages().pop();
    const isCustomHeader = false;
    const pages = uni.$u?.pages ?? [];
    const bottom = sysinfo.safeAreaInsets?.bottom ?? 0;

    // #ifdef H5
    // 兼容说明：h5端第一次获取的高度和第二次获取的高度是有差异 的。
    if (isCustomHeader) {
        height = sysinfo.windowHeight + sysinfo.windowTop;
    } else {
        top = 44;
        if (sysinfo.windowTop > 0) {
            height = sysinfo.windowHeight;
        } else {
            height = sysinfo.windowHeight + sysinfo.windowTop;
        }
    }

    // #endif

    const reulst = {
        bottom: bottom,
        height: height,
        width: sysinfo.windowWidth,
        top: top,
        isCustomHeader: isCustomHeader,
        statusBarHeight: sysinfo.statusBarHeight,
        sysinfo: sysinfo,
    };

    return reulst;
}

export default window;
